<?php

class FileHelper
{
	private $mode = 0755;
	
	public function getMode($mode)
	{
		return $this->mode;
	}
	
	public function setMode($mode)
	{
		$this->mode = $mode;	
	}
	
	
	public function create($file, $data)
	{
		$dir = dirname($file);
		$this->validDir($dir);
		return file_put_contents($file, $data);
	}
	
	public function delete($file)
	{
		if (is_file($file))
		{
			return unlink($file);
		}
	}
	
	public function validDir($dir, $is_create = true)
	{
		$ret = is_dir($dir);
		if (!$ret && $is_create === true)
		{
			$ret = mkdir($dir, $this->mode, true);
		}
		return $ret;
	}
}